import React from 'react';
import { useDispatch } from 'react-redux';
import { AppDispatch } from '../../../store';
import { login } from '../../../actions/userActions';
import AuthForm from '../AuthForm';

const LoginForm: React.FC = () => {
  const dispatch = useDispatch<AppDispatch>();

  const onFinish = async (values: { username: string; password: string }) => {
    try {
      await dispatch(login(values));
      // 处理成功后的逻辑，例如重定向
    } catch (err) {
      console.error('Login failed:', err);
      // 可以显示错误信息给用户
    }
  };

  return <AuthForm onSubmit={onFinish} />;
};

export default LoginForm;